/**
 * content: 接口配置文件
 */
import Axios from 'axios'
// import { Toast } from 'mint-ui'
const axios = Axios
const devApiUrl = 'http://192.168.1.12:8082/'
const testApiUrl = 'http://192.168.1.20:8082/'
const prodApiUrl = 'http://appapi.xx.cn/'

axios.defaults.baseURL = process.env.NODE_ENV === 'development'
  ? devApiUrl : (process.env.NODE_ENV === 'production' ? prodApiUrl : testApiUrl)
axios.defaults.timeout = 4000

// Add a request interceptor
axios.interceptors.request.use(function (config) {
  // Do something before request is sent
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})

// Add a response interceptor
axios.interceptors.response.use(function (response) {
  // Do something with response data
  if (response.data.result !== 0) {
    // let instance = Toast('网络异常~')
    // setTimeout(() => {
    //   instance.close()
    // }, 2000)
  }
  return response.data
}, function (error) {
  // let instance = Toast('网络异常~')
  // setTimeout(() => {
  //   instance.close()
  // }, 2000)
  // Do something with response error
  return Promise.reject(error)
})
export default axios
